package main

import "strconv"

func encode(s []byte) []byte {
	var s2 []byte
	var current byte = 0
	count := 0
	for _, c := range s {
		if c != current  {
			if current != 0 {
				cnt := strconv.Itoa(count)
				s2 = append(s2, []byte(cnt)...)
				s2 = append(s2, current)
			}
			count = 1
			current = c
			continue
		}
		count++
	}
	if current != 0 {
		cnt := strconv.Itoa(count)
		s2 = append(s2, []byte(cnt)...)
		s2 = append(s2, current)
	}
	return s2
}

func countAndSay(n int) string {
	s := []byte{'1'}
	for i := 1; i < n; i++ {
		s = encode(s)
	}
	return string(s)
}

func main() {
	// println(string(encode([]byte("21"))))
	s := countAndSay(4)
	println(s)
}
